<?php

namespace App\Http\Controllers\Admin;

use App\Repositories\FileRepository;
use App\Utils\Output;
use Illuminate\Http\Request;

/**
 * 控制器
 * Class FileController
 * @package App\Http\Controllers\Admin
 */
class FileController extends BaseController
{
    private $rep;

    public function __construct(FileRepository $rep)
    {
        $this->set('file');
        $this->rep = $rep;
    }

    function uploadImage(Request $request)
    {
        return $this->rep->image($request->allFiles(), $request->get('module', 'default'));
    }

    function editerImage(Request $request)
    {
        $result = $this->rep->image($request->allFiles(), $request->get('module', 'default'));
        if ($result->isSuccess()) {
            return Output::data(['src' => $result->data[0]['url']]);
        }
    }
}
